package org.ptkparty.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

public class ProfilPlace extends Place {

	private String name;

	private String player;

	public ProfilPlace(String token) {
		this.name = token;
	}

	public ProfilPlace(String championship, String player) {
		this.name = championship;
		this.player = player;
	}

	public String getName() {
		return name;
	}

	public static class Tokenizer implements PlaceTokenizer<ProfilPlace> {

		@Override
		public String getToken(ProfilPlace place) {
			StringBuilder sb = new StringBuilder(place.getName());
			if (place.getPlayer() != null) {
				sb.append("&").append(place.getPlayer());
			}
			return sb.toString();
		}

		@Override
		public ProfilPlace getPlace(String token) {
			String[] params = token.split("&");
			if (params.length == 1) {
				return new ProfilPlace(params[0]);

			} else if (params.length == 2) {
				return new ProfilPlace(params[0], params[1]);
			}
			return new ProfilPlace("");
		}
	}

	public String getPlayer() {
		return player;
	}
}
